﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using CRM.Entity;
using CRM.BLL;
using DP.Web.UI;
using DP.Common;

namespace CRM.Web.MessagingManage
{
    public partial class FaxShow : Common.PageBase
    {
        private T_FAX_SEND_BLL faxSendBll = new T_FAX_SEND_BLL();
        private T_FAX_SENT_BLL faxSentBll = new T_FAX_SENT_BLL();
        private T_FAX_DMDOC_BLL faxDmdocBll = new T_FAX_DMDOC_BLL();
        private T_FAX_RECV_BLL faxRecvBll = new T_FAX_RECV_BLL();
        T_CONFIG_BLL configBll = new T_CONFIG_BLL();

        protected override void OnInit(EventArgs e)
        {
            base.VerificationRight = false;
            base.OnInit(e);
            PageHelper.SetPrePageUrl(this.Page);
            PageHelper.SetGoBackUrl(this.Page, btnCancel, StaticConstant.NotBackUrl);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                pageDataInit();                
            }
        }

        #region 页面初始化数据绑定




        #endregion

        private void pageDataInit()
        {
            String FAXType = PageHelper.GetQueryString(this.Page, "FAXType");
            string AutoId = PageHelper.GetQueryString(this.Page, "AUTOID");
            switch (FAXType)
            {
                case "SEND":
                    {
                        T_FAX_SEND_Entity faxSendEntity = faxSendBll.GetEntity("AUTOID", AutoId);
                        txtUNAME.Text = faxSendEntity.UNAME;
                        txtFAX.Text = faxSendEntity.FAX;
                        txtPAGES.Text = faxSendEntity.PAGES.ToString();
                        txtSDATE.Text = faxSendEntity.SDATE;
                        txtSTIME.Text = faxSendEntity.STIME;
                        txtSUBJ.Text = faxSendEntity.SUBJ;
                        txtSINFO.Text = faxSendEntity.SINFO;
                        HyperLink hl = new HyperLink();
                        hl.ID = "hlFileName";
                        if (!String.IsNullOrEmpty(faxSendEntity.FILENAME))
                        {
                            hl.Text = GetFileName(faxSendEntity.FILENAME);
                            hl.NavigateUrl = faxSendEntity.FILENAME;
                        }
                        else
                            hl.Visible = false;
                        plFILENAME.Controls.Add(hl);
                    }
                    break;
                case "SENT":
                    {
                        T_FAX_SENT_Entity faxSentEntity = faxSentBll.GetEntity("AUTOID", AutoId);
                        txtUNAME.Text = faxSentEntity.UNAME;
                        txtFAX.Text = faxSentEntity.FAX;
                        txtPAGES.Text = faxSentEntity.PAGES.ToString();
                        txtSDATE.Text = faxSentEntity.SDATE;
                        txtSTIME.Text = faxSentEntity.STIME;
                        txtSUBJ.Text = faxSentEntity.SUBJ;
                        txtSINFO.Text = faxSentEntity.SINFO;
                        HyperLink hl = new HyperLink();
                        hl.ID = "hlFileName";
                        if (!String.IsNullOrEmpty(faxSentEntity.FILENAME))
                        {
                            hl.Text = GetFileName(faxSentEntity.FILENAME);
                            hl.NavigateUrl = faxSentEntity.FILENAME;
                        }
                        else
                            hl.Visible = false;
                        plFILENAME.Controls.Add(hl);
                    }
                    break;
                case "RECEIVE":
                    {
                        T_FAX_RECV_Entity faxRecvEntity = faxRecvBll.GetEntity("AUTOID", AutoId);
                        txtUNAME.Text = faxRecvEntity.UNAME;
                        txtFAX.Text = faxRecvEntity.FAX;
                        txtPAGES.Text = faxRecvEntity.PAGES.ToString();
                        txtSDATE.Text = faxRecvEntity.SDATE;
                        txtSTIME.Text = faxRecvEntity.STIME;
                        txtSUBJ.Text = faxRecvEntity.SUBJ;
                        txtSINFO.Text = faxRecvEntity.SINFO;
                        if (!String.IsNullOrEmpty(faxRecvEntity.FILENAME))
                        {
                            string[] fileNames = faxRecvEntity.FILENAME.Split(new char[] { ',', ';' });
                            foreach (string fileName in fileNames)
                            {
                                if (!String.IsNullOrEmpty(fileName))
                                {
                                    HyperLink hl = new HyperLink();
                                    hl.ID = "hlFileName" + fileName;
                                    hl.Text = GetFileName(fileName);
                                    hl.NavigateUrl = configBll.GetFaxPath(this.Page, fileName);
                                    plFILENAME.Controls.Add(hl);
                                    plFILENAME.Controls.Add(new LiteralControl("<br />"));

                                }
                            }
                        }
                        
                    }
                    break;
            }
        }

        private string GetFileName(string input)
        {
            return input.Substring(input.LastIndexOf("\\") + 1);
        }

    }
}

